//javascript: void((function() {var element = document.createElement('script');element.id = 'table2excel';element.charset = 'utf-8',element.setAttribute('src', 'http://127.0.0.1/tools-for-js/Table2Excel.js?' + Date.parse(new Date()));document.body.appendChild(element);})())
function Table2Excel(doc, oTable)
{ 
	try{
		var oApp = new ActiveXObject("Excel.Application"); 
		if (oApp)
		{
			var oWB = oApp.Workbooks.Add(); 
			var oSheet = oWB.ActiveSheet; 

			var rows = oTable.rows.length; 
			for (i = 0; i < rows; i++) 
			{ 
				var cols = oTable.rows(i).cells.length; 
				for (j = 0; j < cols; j++) 
				{ 
					oSheet.Cells(i + 1, j + 1).value = oTable.rows(i).cells(j).innerText; 
				} 
			} 
			oApp.Visible = true;
		}
	}
	catch(e)
	{
		alert("请确定允许了ActiveX运行");
	}
}


function HackWindow(_window)
{
	for (var i = 0 ; i < _window.frames.length ; i++)
	{
		if(_window.frames[i].contentWindow)
		{
			HackWindow(_window.frames[i].contentWindow);
		}
		else
		{
			HackWindow(_window.frames[i]);
		}
	}
	
	HackDocument(_window.document);	
}

function AddExportMenu(table, index)
{
	doc = table.ownerDocument ;
	var node = doc.createElement("button");
	node.id = "menu_export_table_" + index ;
	node.innerHTML = "Export Excel ..." ;
	node.index = index ;
	node.onclick = function () {
		var index = this.index;
		doc = this.ownerDocument ;
		var table = doc.getElementsByTagName("TABLE")[index];
		Table2Excel(doc, table);
		};
	//doc.body.appendChild(node, table);
	table.parentNode.insertBefore(node, table);
}

function HackDocument(doc)
{
	var tables = doc.getElementsByTagName('TABLE');
	for(var i = 0 ; i < tables.length; i++)
	{
		var table = tables[i] ;
		AddExportMenu(table, i) ;
	}
}


function HackLogic()
{
	HackWindow(window);
}

HackLogic() ;
alert("Load finished.");